// local control sets
pause off
forv q = 1/ $qLags {
	local vlist1 `vlist1' c.l`q'_X_TaxcutToGDP
}
di "`vlist1'"

* other macro controls
forv p = 1/$pLags {
	foreach var in $controlist {						
				local vlist2 `vlist2' c.l`p'd_`var'
	}
}
di "`vlist2'"

if missing(`"$controlist"') {
	forv p = 1/$pLags {
		foreach var in $controlist1 {
			local vlist2 `vlist2' c.l`p'_`var'
		}
	}

	forv p = 1/$pLags {
		foreach var in $controlist2 {           
				local vlist2 `vlist2' c.l`p'd_`var'					
		}
	}
	di "`vlist2'"
}


* add WWII dummy or not
local vlist3 
if $dummyWWII == 1 {
	local vlist3 `vlist3' dummyWWII
	di "`vlist3'"
	
}


* spending controls
local vlist4

if $spendControl == 1 { 
		if missing("$gLags") {		
		global gLags = $pLags	
	}
	
	forv g = 0/$gLags {
			
			if $gLeads == 0 {
			local vlist4 `vlist4' c.l`g'_${spendControlVar}
			}
			
			if $gLeads == 1 {
			local vlist4 `vlist4' c.f`g'_${spendControlVar}
			}
	}
}
di "`vlist4'"

local hirf = ${hmax} - 1

cap drop Quarters Zero
qui gen Quarters = _n       if _n<= $hmax
qui gen Zero =  0           if _n<= $hmax

qui forv j = 0/1 {
	cap drop b`j' v`j' 
	cap drop u${alpha1}`j' d${alpha1}`j' 
	cap drop u${alpha2}`j' d${alpha2}`j'
	gen b`j'=0
	gen v`j' = 0
	gen u${alpha1}`j'=0 
	gen d${alpha1}`j'=0
	if ${cfbands} == 2 {
		gen u${alpha2}`j'=0
		gen d${alpha2}`j'=0
	}
}


if "${LHS}" == "raw" {

	forv h = 0/`hirf' {
					
		${Quiet} regress ${depvar}`h' i.Regime`h'#(c.X_TaxcutToGDP `vlist1' `vlist2' `vlist4') `vlist3' i.Regime`h', vce(robust)
			
		qui forv j = 0/1 {
			replace b`j' = _b[`j'.Regime#c.X_TaxcutToGDP]    if _n == `h'+1
			replace v`j' = _se[`j'.Regime#c.X_TaxcutToGDP]    if _n == `h'+1
		}

		qui forv j = 0/1 {
			replace u${alpha1}`j' = b`j' + ${zscore1}* v`j'  if _n == `h'+1
			replace d${alpha1}`j' = b`j' - ${zscore1}* v`j'  if _n == `h'+1
			if ${cfbands} == 2 {
				replace u${alpha2}`j' = b`j' + ${zscore2} * v`j'     if _n == `h'+1
				replace d${alpha2}`j' = b`j' - ${zscore2} * v`j'     if _n == `h'+1
			}
		}
		
		// Significance test
		test 0.Regime#c.X_TaxcutToGDP = 0

	}

	forvalues r = 0/1 {
	
	global j = `r'
	
	if ${PlotIRF} == 1 {
		do ${dofilepath}/Plot_IRF_StateDep.do
	}
	
	}

}

else if "${LHS}" == "smoothed" {

	forv h = 0/`hirf' {

		${Quiet} regress f`h'${depvar}smooth i.Regime`h'#(c.X_TaxcutToGDP `vlist1' `vlist2' `vlist4') `vlist3' i.Regime`h', vce(robust)	
	
		qui forv j = 0/1 {
			replace b`j' = _b[`j'.Regime#c.X_TaxcutToGDP]    if _n == `h'+1
			replace v`j' = _se[`j'.Regime#c.X_TaxcutToGDP]    if _n == `h'+1
		}

		qui forv j = 0/1 {
			replace u${alpha1}`j' = b`j' + ${zscore1}* v`j'  if _n == `h'+1
			replace d${alpha1}`j' = b`j' - ${zscore1}* v`j'  if _n == `h'+1
			if ${cfbands} == 2 {
				replace u${alpha2}`j' = b`j' + ${zscore2} * v`j'     if _n == `h'+1
				replace d${alpha2}`j' = b`j' - ${zscore2} * v`j'     if _n == `h'+1
			}
		}
		
		// Significance tests
		test 0.Regime#c.X_TaxcutToGDP = 0
		test 0.Regime#c.X_TaxcutToGDP = 0
		test 0.Regime#c.X_TaxcutToGDP = 1.Regime#c.X_TaxcutToGDP

	}

	forvalues r = 0/1 {
	
	global j = `r'
	
	if ${PlotIRF} == 1 {
		do ${dofilepath}/Plot_IRF_StateDep.do
	}
	
	}
}

